layui.use(['form','layer'],function(){
	
	var form = layui.form,layer=layui.layer;
	
	var testRunStatus = {"1":"待执行","2":"执行中","3":"成功","4":"失败"};
	
	createTastRunReport();
	
	function createTastRunReport(){
		
		var url = "../report/getTastRunReport";
		ajaxPost(url,{},function(data){
			createCharts(data.data);
		},function(data){
             layer.alert(data.errorMsg, {
				icon: 5,
				title: "错误"
				});
		});
	}
	
	
	function createCharts(data){
		$("#taskreport").empty();
		for(var key in data){
			var tasks = key.split("-");
			if(tasks.length != 2)
				return ;
			
			var chartId = "main"+tasks[0];
			$('<div id="'+chartId+'" style="width: 350px;height:100%;display:inline-block;"></div>').appendTo($("#taskreport"));
			var taskName = tasks[1];
			var legendData = [];
			var seriesData = [];
			
			var statusData = data[key];
			for(var i = 0;i< statusData.length;i++){
				var status = statusData[i].taskRunStatus;
				var num = statusData[i].taskRunNum;
				legendData.push(testRunStatus[status]);
				seriesData.push({"value":num,"name":testRunStatus[status]});
			}
			
			var option = {
			    title: {
			        text: taskName+'\n测试任务完成统计',
			        left: 'center'
			    },
			    tooltip : {
			        trigger: 'item',
			        formatter: "{b} : {c} ({d}%)"
			    },
			    legend: {
			        // orient: 'vertical',
			        // top: 'middle',
			        bottom: 10,
			        left: 'center',
			        data: legendData
			    },
			    series : [
			        {
			            type: 'pie',
			            radius : '65%',
			            center: ['50%', '50%'],
			            selectedMode: 'single',
			            data:seriesData,
			            itemStyle: {
			                emphasis: {
			                    shadowBlur: 10,
			                    shadowOffsetX: 0,
			                    shadowColor: 'rgba(0, 0, 0, 0.5)'
			                }
			            }
			        }
			    ]
			};
			
			 var myCharts = echarts.init(document.getElementById(chartId));
			 myCharts.setOption(option);
		}
	}
});